package com.xrf;

import android.app.Dialog;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.SeekBar;
import android.widget.TextView;
import com.example.mobilemap.R;
import com.example.mobilemap.Utility.ConstValue;
import com.example.mobilemap.Utility.GlobalValues;
import com.example.mobilemap.Utility.MapUtil;
import butterknife.BindView;
import butterknife.ButterKnife;

public class LayerCtrlDlg extends Dialog implements SeekBar.OnSeekBarChangeListener {
    @BindView(R.id.seekbar_layerctrl_image)
    SeekBar seekBarImage;
    @BindView(R.id.seekbar_layerctrl_points)
    SeekBar seekBarPoints;
    @BindView(R.id.seekbar_layerctrl_thematic)
    SeekBar seekBarThematic;
    @BindView(R.id.seekbar_layerctrl_river)
    SeekBar seekBarRiver;
    @BindView(R.id.text_layerctrl_image)
    TextView textImage;
    @BindView(R.id.text_layerctrl_points)
    TextView textPoints;
    @BindView(R.id.text_layerctrl_thematic)
    TextView textThematic;
    @BindView(R.id.text_layerctrl_river)
    TextView textRiver;
    
    private Context context;
    
    public LayerCtrlDlg(Context context) {
        super(context, R.style.MyBaseDialog);
        this.context = context;
        
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.dlg_layer_display_ctrl, null);
        setContentView(view);
        ButterKnife.bind(this);
        
        seekBarThematic.setProgress((int) (
                MapUtil.getInstance().getGraphicsOverlayOpacity(1) * 100.0));
        textThematic.setText(String.valueOf((int)(MapUtil.getInstance().getGraphicsOverlayOpacity(1) * 100.0)));
        
        seekBarPoints.setProgress((int) (
                MapUtil.getInstance().getGraphicsOverlayOpacity() * 100.0));
        textPoints.setText(String.valueOf((int)(MapUtil.getInstance().getGraphicsOverlayOpacity() * 100.0)));
        
        seekBarImage.setProgress((int)(
                MapUtil.getInstance().getLayerbyIndex(ConstValue.Layer_Image_Index).getOpacity() * 100.0));
        textImage.setText(String.valueOf((int)(MapUtil.getInstance().getLayerbyIndex(ConstValue.Layer_Image_Index).getOpacity() * 100.0)));
        
        seekBarRiver.setProgress(100);
        textRiver.setText(String.valueOf((int)(MapUtil.getInstance().getLayerbyIndex(ConstValue.Layer_Vector_Index).getOpacity() * 100.0)));
        
        seekBarImage.setOnSeekBarChangeListener(this);
        seekBarPoints.setOnSeekBarChangeListener(this);
        seekBarThematic.setOnSeekBarChangeListener(this);
        seekBarRiver.setOnSeekBarChangeListener(this);
    }
    
    @Override
    public void onProgressChanged(SeekBar var1, int var2, boolean var3) {
        switch (var1.getId()) {
            case R.id.seekbar_layerctrl_thematic:
                MapUtil.getInstance().setGraphicsOverlayOpacity((float) ((float) var2 / 100.0), 1);
                textThematic.setText(Integer.toString(var2));
                break;
            case R.id.seekbar_layerctrl_image:
                MapUtil.getInstance().setLayerOpacity(
                        MapUtil.getInstance().getLayerbyIndex(ConstValue.Layer_Image_Index).getName(),
                        (float) ((float) var2 / 100.0));
                textImage.setText(Integer.toString(var2));
                break;
            case R.id.seekbar_layerctrl_points:
                MapUtil.getInstance().setGraphicsOverlayOpacity((float) ((float) var2 / 100.0));
                textPoints.setText(Integer.toString(var2));
                break;
            case R.id.seekbar_layerctrl_river:
                textRiver.setText(Integer.toString(var2));
                break;
            default:
                break;
        }
    }
    
    @Override
    public void onStartTrackingTouch(SeekBar var1) {
        return;
    }
    
    @Override
    public void onStopTrackingTouch(SeekBar var1) {
        return;
    }
    
    public void showDlg() {
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        if (lp == null)
            return;
        lp.width = (int) (GlobalValues.getInstance().getMainActivityWidth() * 0.8);
        lp.height = (int) (GlobalValues.getInstance().getMainActivityHeight() * 0.3);
        getWindow().setAttributes(lp);
        Log.d("admin", "LayerCtrlDlg width: " + lp.width + "; height: " + lp.height);
        this.show();
    }
}